import Koa from 'koa';
import KoaStatic from 'koa-static';
import baseConfig from '../config/server';
import MouseRoute from './route/house';
import errorHandler from './middleware/errorHandler';
import path from 'path';
const app = new Koa();

app.use(async (ctx, next) => {
    ctx.set({
        'Access-Control-Aloow-Methods': 'GET,POST,HEAD,OPTIONS',
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Max-Age': (1000 * 60 * 60 * 24 * 7).toString(),
    });
    await next();
});
app.use(
    KoaStatic(path.join(__dirname, './public'), {
        maxAge: 1000 * 60 * 60 * 24 * 7,
    })
);
app.use(
    KoaStatic(path.join(__dirname, '../public'), {
        maxAge: 1000 * 60 * 60 * 24 * 7,
    })
);
app.use(
    KoaStatic(path.join(__dirname, './public/public'), {
        maxAge: 1000 * 60 * 60 * 24 * 7,
    })
);

app.use(errorHandler);
app.use(MouseRoute.routes());

app.listen(baseConfig.server.port, () => {
    console.log(`${baseConfig.server.protocol}://${baseConfig.server.host}:${baseConfig.server.port}`);
});
export default app;
